<!DOCTYPE html>
<html lang="en">

<head>
    <title>学生登录</title>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">

    <meta http-equiv="cache-control" content="max-age=0" />
    <meta http-equiv="cache-control" content="no-cache" />
    <meta http-equiv="expires" content="0" />
    <meta http-equiv="expires" content="Tue, 01 Jan 1980 1:00:00 GMT" />
    <meta http-equiv="pragma" content="no-cache" />


    <!--360浏览器使用极速模式-->
    <meta name="renderer" content="webkit"/>

    <script src="/jojo_cdn/vendors/jquery/jquery.min.js"></script>
    <script type="text/javascript" src="/jojo_cdn/jslib/csrf.js"></script>

    <script src="/jojo_cdn/vendors/bootstrap/js/bootstrap.min.js"></script>
    <script src="/jojo_cdn/jslib/bootstrap/bootstrap-dialog.min.cn.js"></script>

    <script type="text/javascript">
        needCsrfCookie();
    </script>

    <link type="text/css" rel="stylesheet" href="/jojo_cdn/vendors/font-awesome/css/font-awesome.min.css">
    <link type="text/css" rel="stylesheet" href="/jojo_cdn/vendors/bootstrap/css/bootstrap.min.css">
    <link type="text/css" rel="stylesheet" href="/jojo_cdn/login/student/css/login.css">
    <style>
        body {
            font-family: "Microsoft Yahei",Arial ;

            /*background-color: #EEEEEE;*/
        }
        .modal-dialog {
            z-index: 1060;
        }
    </style>
</head>

<body oncontextmenu="return false" >

    <div id="page-container" >

        <h1 style="color:#ffffff;font-family: 微软雅黑;">学生登录</h1>
        <form action="index.html" class="form" autocomplete="off">
            <div>
                <input type="text" name="username" id="username"  class="username"  maxlength="20"
                       placeholder="用户名" autocomplete="off"    />
            </div>
            <div>
                <input type="password" name="password" id="password" class="password" placeholder="密码" maxlength="20"
                       oncontextmenu="return false" onpaste="return false" autocomplete="off" />
            </div>
            <div>

                <button id="submit" type="button" onclick="postLoginRequest()">登录</button>
            </div>
            <br/>
            <br/>
            <div id="reg-for">
                <ul>
                    <!--<li style="margin-left: 22px;">-->
                        <!--<a style="color:white;" href="/student/register/reg.html" target="_blank">新用户注册</a>-->
                    <!--</li>-->
                    <!--<li>-->
                        <!--<a style="color:white;" href="/forgetpwd/forgetpwd.html" target="_blank">忘记密码?</a>-->
                    <!--</li>-->
                </ul>

            </div>
    </form>

    </div>
    <div class="alert" style="display:none;">
        <h2>消息</h2>
        <div class="alert_con">
            <p id="ts"></p>
            <p style="line-height:70px"><a class="btn">确定</a></p>
        </div>
    </div>




<script>
    $(".btn").click(function(){
        is_hide();
    });


    function postLoginRequest(){


        $.ajax({
            //提交的网址
            url: '/api/student/loginreq',

            type: 'POST',

            data:
            'username=' + encodeURIComponent($('#username').val()) +
            '&password=' + encodeURIComponent($('#password').val()) ,

            //成功返回之后调用的函数
            success: function(ret) {

                if (ret.retcode==0) {
                    window.location.href = '/student/index.html';
                }
                else {
                    BootstrapDialog.alert("登录失败 : " + ret.reason);
//                    $("#username").val("");
                    $("#password").val("");
                }
            },
            error:function (xhr, ajaxOptions, thrownError){
                BootstrapDialog.alert('错误: ' + xhr.status + thrownError)
            }
        });
    }

    function isIE () {
        var myNav = navigator.userAgent.toLowerCase();
        return (myNav.indexOf('msie') != -1) ? parseInt(myNav.split('msie')[1]) : false;
    }
    function is_hide(){ $(".alert").animate({"top":"-40%"}, 300) }
    function is_show(){ $(".alert").show().animate({"top":"45%"}, 300) }

    window.onload = function()
    {
        if (isIE()) {
            BootstrapDialog.alert("\n\n您使用的IE浏览器已经过时了哦.\n\n如果您使用的是360、搜狗浏览器，请选择极速模式\n\n" +
            "<a href='http://rj.baidu.com/soft/detail/14744.html?ald' target='_blank'>推荐您使用谷歌浏览器,点击下载</a>\n\n");
        }
    };



    //Enter事件
    function curTimestamp() {
        var theDate = new Date().getTime();
        return Math.floor(theDate / 1000);
    }

    var lastSendReqTime = 0;


    document.onkeydown = function(event) {
        var holder;
        //IE uses this
        if(window.event) {
            holder = window.event.keyCode;
        }
        //FF uses this
        else {
            holder = event.which;
        }
        keydown_handle(holder);
    };

    $(function() {
        $("input").on("keydown", function (e) {
            return e.which !== 32;
        });
    });

    function keydown_handle(key){

        // 防止过快按回车， 限制2秒内，
        if(key == 13){

            var curTime = curTimestamp();
            if ( (curTime-window.lastSendReqTime) < 4 ){
                return;
            }
            window.lastSendReqTime = curTime;

            postLoginRequest();
        }
        //禁止空格输入
        else if(key===32) return false;
    }
</script>

</body>


</html>